﻿using HealthcareSystem.API.Write.Application.Command.MetricsCommands;
using HealthcareSystem.Domain.BasicSettings.Metrics;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.MetricsCommands
{
    /// <summary>
    /// 指标逻辑删除请求
    /// </summary>
    public class MetricsDeleteCommandHandler : IRequestHandler<MetricsDeleteCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Metricss> metssRep;

        public MetricsDeleteCommandHandler(IBaseRepository<Metricss> metssRep)
        {
            this.metssRep = metssRep;
        }

        public async Task<ApiResult<int>> Handle(MetricsDeleteCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.Success;
            result.Message=ResultCode.Error.ToString();

            var res=metssRep.GetAll().FirstOrDefault(x=>x.MetricsId==request.MetricsId);
            res.IsDeleted=true;
            await metssRep.UpdAsync(res);

            return await Task.FromResult(result);

        }

    }
}
